﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;

namespace yfxt
{
    public partial class cx_lstj : Form
    {
        public cx_lstj()
        {
            InitializeComponent();
        }

        string sql_lstj;
        public static int ypxh;
        DataTable dt_tjjl = new DataTable();
        #region 主界面加载
        private void cx_lstj_Load(object sender, EventArgs e)
        {
            comboBox1.Items.Add("全部");
            comboBox1.Items.Add("西药");
            comboBox1.Items.Add("中成药");
            comboBox1.Items.Add("中草药");
            button2.Enabled = false;
        }
        #endregion

        #region 退出
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion

        #region 检索
        private void button1_Click(object sender, EventArgs e)
        {
            dt_tjjl.Clear();
            try
            {
                sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                dataGridView1.DataSource = dt_tjjl;
                ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                button2.Enabled = true;
            }
            catch
            {
                return;

            }
        }
        #endregion 

        #region 调价列表
        private void button2_Click(object sender, EventArgs e)
        {
            cx_lstj_tjlb tjlb = new cx_lstj_tjlb();
            tjlb.Show();
        }
        #endregion

        private void textBox1_KeyUp(object sender, KeyEventArgs e)
        {
            if (comboBox1.Text.Trim() == "")
            {
                dt_tjjl.Clear();
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "b.pydm like '" + textBox1.Text.Trim() + "%' and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                }
                catch
                {
                    return;
                }
                
 
            }
            if (comboBox1.Text.Trim() == "全部")
            {
                dt_tjjl.Clear();
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "b.pydm like '" + textBox1.Text.Trim() + "%' and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                }
                catch
                {
                    return;
                }


            }
            if (comboBox1.Text.Trim() == "西药")
            {
                dt_tjjl.Clear();
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "b.type=1 and "+
                "b.pydm like '" + textBox1.Text.Trim() + "%' and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                }
                catch
                {
                    return;
                }

            }
            if (comboBox1.Text.Trim() == "中成药")
            {
                dt_tjjl.Clear();
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "b.type=2 and "+
                "b.pydm like '" + textBox1.Text.Trim() + "%' and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                }
                catch
                {
                    return;
                }


            }
            if (comboBox1.Text.Trim() == "中草药")
            {
                dt_tjjl.Clear();
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                "yf_tjjl a," +
                "yk_typk b," +
                "yk_cddz c where " +
                "a.ypxh=b.ypxh and " +
                "a.ypcd=c.ypcd and " +
                "b.type=3 and "+
                "b.pydm like '" + textBox1.Text.Trim() + "%' and " +
                "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                }
                catch
                {
                    return;
                }


            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            dt_tjjl.Clear();
            if (comboBox1.Text.Trim() == "全部")
            {
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                    "yf_tjjl a," +
                    "yk_typk b," +
                    "yk_cddz c where " +
                    "a.ypxh=b.ypxh and " +
                    "a.ypcd=c.ypcd and " +
                    "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                    "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                    "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                    button2.Enabled = true;
                }
                catch
                {
                    return;

                }
             }
            if (comboBox1.Text.Trim() == "西药")
            {
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                    "yf_tjjl a," +
                    "yk_typk b," +
                    "yk_cddz c where " +
                    "a.ypxh=b.ypxh and " +
                    "a.ypcd=c.ypcd and " +
                    "b.type=1 and "+
                    "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                    "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                    "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                    button2.Enabled = true;
                }
                catch
                {
                    return;

                }
            }
            if (comboBox1.Text.Trim() == "中成药")
            {
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                    "yf_tjjl a," +
                    "yk_typk b," +
                    "yk_cddz c where " +
                    "a.ypxh=b.ypxh and " +
                    "a.ypcd=c.ypcd and " +
                    "b.type=2 and "+
                    "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                    "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                    "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                    button2.Enabled = true;
                }
                catch
                {
                    return;

                }
            }
            if (comboBox1.Text.Trim() == "中草药")
            {
                try
                {
                    sql_lstj = "select distinct b.pydm,b.ypmc,b.ypgg,b.ypdw,c.cdmc,b.ypxh,b.jxdm from " +
                    "yf_tjjl a," +
                    "yk_typk b," +
                    "yk_cddz c where " +
                    "a.ypxh=b.ypxh and " +
                    "a.ypcd=c.ypcd and " +
                    "b.type=3 and "+
                    "tjrq>='" + dateTimePicker1.Value.ToShortDateString() + "' and " +
                    "tjrq<='" + dateTimePicker2.Value.ToShortDateString() + "' and " +
                    "a.yfsb='" + mainform.yfsb + "'";

                    dt_tjjl.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sql_lstj, null));
                    dataGridView1.Columns[0].DataPropertyName = dt_tjjl.Columns[0].ToString();
                    dataGridView1.Columns[1].DataPropertyName = dt_tjjl.Columns[1].ToString();
                    dataGridView1.Columns[2].DataPropertyName = dt_tjjl.Columns[2].ToString();
                    dataGridView1.Columns[3].DataPropertyName = dt_tjjl.Columns[3].ToString();
                    dataGridView1.Columns[4].DataPropertyName = dt_tjjl.Columns[4].ToString();
                    dataGridView1.Columns[5].DataPropertyName = dt_tjjl.Columns[5].ToString();
                    dataGridView1.Columns[6].DataPropertyName = dt_tjjl.Columns[6].ToString();
                    dataGridView1.DataSource = dt_tjjl;
                    ypxh = int.Parse(dt_tjjl.Rows[dataGridView1.CurrentRow.Index]["ypxh"].ToString());
                    button2.Enabled = true;
                }
                catch
                {
                    return;

                }
            }
        }
    }
}
